package com.wems.dev_ops_manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wems.dev_ops_manage.domain.vo.FaultRecordVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wems.common.annotation.Log;
import com.wems.common.core.controller.BaseController;
import com.wems.common.core.domain.AjaxResult;
import com.wems.common.enums.BusinessType;
import com.wems.dev_ops_manage.domain.FaultRecord;
import com.wems.dev_ops_manage.service.IFaultRecordService;
import com.wems.common.utils.poi.ExcelUtil;
import com.wems.common.core.page.TableDataInfo;

/**
 * 故障记录Controller
 * 
 * @author MPC
 * @date 2025-04-05
 */
@RestController
@RequestMapping("/fault_record/fault_record")
public class FaultRecordController extends BaseController
{
    @Autowired
    private IFaultRecordService faultRecordService;

    /**
     * 查询故障记录列表
     */
    @PreAuthorize("@ss.hasPermi('fault_record:fault_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultRecord faultRecord)
    {
        startPage();
        List<FaultRecordVo> list = faultRecordService.selectFaultRecordVoList(faultRecord);
        return getDataTable(list);
    }

    /**
     * 导出故障记录列表
     */
    @PreAuthorize("@ss.hasPermi('fault_record:fault_record:export')")
    @Log(title = "故障记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultRecord faultRecord)
    {
        List<FaultRecord> list = faultRecordService.selectFaultRecordList(faultRecord);
        ExcelUtil<FaultRecord> util = new ExcelUtil<FaultRecord>(FaultRecord.class);
        util.exportExcel(response, list, "故障记录数据");
    }

    /**
     * 获取故障记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('fault_record:fault_record:query')")
    @GetMapping(value = "/{faultId}")
    public AjaxResult getInfo(@PathVariable("faultId") Long faultId)
    {
        return success(faultRecordService.selectFaultRecordByFaultId(faultId));
    }

    /**
     * 新增故障记录
     */
    @PreAuthorize("@ss.hasPermi('fault_record:fault_record:add')")
    @Log(title = "故障记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultRecord faultRecord)
    {
        return toAjax(faultRecordService.insertFaultRecord(faultRecord));
    }

    /**
     * 修改故障记录
     */
    @PreAuthorize("@ss.hasPermi('fault_record:fault_record:edit')")
    @Log(title = "故障记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultRecord faultRecord)
    {
        return toAjax(faultRecordService.updateFaultRecord(faultRecord));
    }

    /**
     * 删除故障记录
     */
    @PreAuthorize("@ss.hasPermi('fault_record:fault_record:remove')")
    @Log(title = "故障记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{faultIds}")
    public AjaxResult remove(@PathVariable Long[] faultIds)
    {
        return toAjax(faultRecordService.deleteFaultRecordByFaultIds(faultIds));
    }
}
